package com.micro.frog.fortune.listner;

import com.micro.frog.fortune.util.DbUtil;
import javax.annotation.Nonnull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

/**
 * @author jason.lv
 * @since 2022/2/22 14:45
 */
@Slf4j
@Service
public class SqlIniter implements ApplicationListener<ApplicationReadyEvent> {

    @Override
    public void onApplicationEvent(@Nonnull ApplicationReadyEvent event) {
        try {
            DbUtil.execute();
        } catch (Exception e) {
            log.error("SQL 初始化错误", e);
            System.exit(-1);
        }

    }
}
